package com.biz;

import java.util.List;

import com.dao.IOrdersDao;
import com.dao.IOsDetailsDao;
import com.dao.OrdersDaoImpl;
import com.dao.OsDetailsDaoImpl;
import com.entity.Orders;
import com.entity.OrdersDetails;
import com.util.PageBean;

public class OrdersBizImpl implements IOrdersBiz {
	IOrdersDao osdao=new OrdersDaoImpl();
	IOsDetailsDao odsdao=new OsDetailsDaoImpl();
	@Override
	public PageBean<Orders> showOrdersByPage(int currPage, int pageSize, String uid) {
		// TODO Auto-generated method stub
		PageBean<Orders> pb=new PageBean<Orders>();
		pb.setCurrPage(currPage);
		pb.setPageSize(pageSize);
		pb.setList(osdao.showOrdersByPage(currPage, pageSize, uid));
		for (Orders os : pb.getList()) {
			os.setOdlist(odsdao.getAllOrdersDetails(os.getId()));
		}
		pb.setTotalRow(osdao.getOrdersCount(uid));
		return pb;
	}

	@Override
	public int addOrder(Orders os,List<OrdersDetails> odslist) {
		// TODO Auto-generated method stub
		int isadd=0;
		if(osdao.addOrder(os)>0){
			for (OrdersDetails ods : odslist) {
				ods.setOid(""+osdao.getAddOrderId(os.getUid()));
				odsdao.addOrdersDetails(ods);
				isadd++;
			}
		}
		return isadd==odslist.size()?1:-1;
	}

	@Override
	public int delOrder(String id) {
		// TODO Auto-generated method stub
		return osdao.delOrder(id);
	}

	@Override
	public Orders getOrder(String id) {
		// TODO Auto-generated method stub
		return osdao.getOrder(id);
	}

	@Override
	public int modOrderState_1(String id) {
		// TODO Auto-generated method stub
		return osdao.modOrderState_1(id);
	}

	@Override
	public int modOrderState_2(String id) {
		// TODO Auto-generated method stub
		return osdao.modOrderState_2(id);
	}

}
